from django.db import models


class PointRecord0(models.Model):
    '''用户积分记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '收入'),
        (2, '支出'),
        (3, '已过期')
    )

    POINT_TYPE_CHOICES = (
        (1, '注册'),
        (2, '消费'),
        (3, '邀请'),
        (4, '活动'),
        (5, '签到')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    operate_type = models.SmallIntegerField(verbose_name='收支类型', choices=OPERATE_TYPE_CHOICES)
    point_type = models.SmallIntegerField(verbose_name='积分类型', choices=POINT_TYPE_CHOICES, default=2)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    point_balance = models.DecimalField(verbose_name='积分余额', max_digits=10, decimal_places=2, default=0)
    point_order = models.CharField(verbose_name='关联订单', max_length=64, null=True, blank=True)
    expired_time = models.DateTimeField(verbose_name='过期时间', null=True, blank=True)
    explain = models.CharField(verbose_name='说明', max_length=64)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='消费商户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='交易金额', max_digits=10, decimal_places=2, default=0)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    shop_id = models.CharField(verbose_name='商户id', max_length=32, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=32, null=True, blank=True)
    level = models.ForeignKey('users.Level', on_delete=models.SET_NULL, verbose_name='层级', null=True, blank=True)

    class Meta:
        db_table = 'tb_point_record_0'
        verbose_name = '用户积分记录'
        verbose_name_plural = verbose_name


class PointRecord1(models.Model):
    '''用户积分记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '收入'),
        (2, '支出'),
        (3, '已过期')
    )

    POINT_TYPE_CHOICES = (
        (1, '注册'),
        (2, '消费'),
        (3, '邀请'),
        (4, '活动'),
        (5, '签到')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    operate_type = models.SmallIntegerField(verbose_name='收支类型', choices=OPERATE_TYPE_CHOICES)
    point_type = models.SmallIntegerField(verbose_name='积分类型', choices=POINT_TYPE_CHOICES, default=2)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    point_balance = models.DecimalField(verbose_name='积分余额', max_digits=10, decimal_places=2, default=0)
    point_order = models.CharField(verbose_name='关联订单', max_length=64, null=True, blank=True)
    expired_time = models.DateTimeField(verbose_name='过期时间', null=True, blank=True)
    explain = models.CharField(verbose_name='说明', max_length=64)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='消费商户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='交易金额', max_digits=10, decimal_places=2, default=0)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    shop_id = models.CharField(verbose_name='商户id', max_length=32, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=32, null=True, blank=True)
    level = models.ForeignKey('users.Level', on_delete=models.SET_NULL, verbose_name='层级', null=True, blank=True)

    class Meta:
        db_table = 'tb_point_record_1'
        verbose_name = '用户积分记录'
        verbose_name_plural = verbose_name


class PointRecord2(models.Model):
    '''用户积分记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '收入'),
        (2, '支出'),
        (3, '已过期')
    )

    POINT_TYPE_CHOICES = (
        (1, '注册'),
        (2, '消费'),
        (3, '邀请'),
        (4, '活动'),
        (5, '签到')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    operate_type = models.SmallIntegerField(verbose_name='收支类型', choices=OPERATE_TYPE_CHOICES)
    point_type = models.SmallIntegerField(verbose_name='积分类型', choices=POINT_TYPE_CHOICES, default=2)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    point_balance = models.DecimalField(verbose_name='积分余额', max_digits=10, decimal_places=2, default=0)
    point_order = models.CharField(verbose_name='关联订单', max_length=64, null=True, blank=True)
    expired_time = models.DateTimeField(verbose_name='过期时间', null=True, blank=True)
    explain = models.CharField(verbose_name='说明', max_length=64)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='消费商户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='交易金额', max_digits=10, decimal_places=2, default=0)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    shop_id = models.CharField(verbose_name='商户id', max_length=32, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=32, null=True, blank=True)
    level = models.ForeignKey('users.Level', on_delete=models.SET_NULL, verbose_name='层级', null=True, blank=True)

    class Meta:
        db_table = 'tb_point_record_2'
        verbose_name = '用户积分记录'
        verbose_name_plural = verbose_name


class PointRecord3(models.Model):
    '''用户积分记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '收入'),
        (2, '支出'),
        (3, '已过期')
    )

    POINT_TYPE_CHOICES = (
        (1, '注册'),
        (2, '消费'),
        (3, '邀请'),
        (4, '活动'),
        (5, '签到')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    operate_type = models.SmallIntegerField(verbose_name='收支类型', choices=OPERATE_TYPE_CHOICES)
    point_type = models.SmallIntegerField(verbose_name='积分类型', choices=POINT_TYPE_CHOICES, default=2)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    point_balance = models.DecimalField(verbose_name='积分余额', max_digits=10, decimal_places=2, default=0)
    point_order = models.CharField(verbose_name='关联订单', max_length=64, null=True, blank=True)
    expired_time = models.DateTimeField(verbose_name='过期时间', null=True, blank=True)
    explain = models.CharField(verbose_name='说明', max_length=64)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='消费商户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='交易金额', max_digits=10, decimal_places=2, default=0)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    shop_id = models.CharField(verbose_name='商户id', max_length=32, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=32, null=True, blank=True)
    level = models.ForeignKey('users.Level', on_delete=models.SET_NULL, verbose_name='层级', null=True, blank=True)

    class Meta:
        db_table = 'tb_point_record_3'
        verbose_name = '用户积分记录'
        verbose_name_plural = verbose_name


class PointRecord4(models.Model):
    '''用户积分记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '收入'),
        (2, '支出'),
        (3, '已过期')
    )

    POINT_TYPE_CHOICES = (
        (1, '注册'),
        (2, '消费'),
        (3, '邀请'),
        (4, '活动'),
        (5, '签到')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    operate_type = models.SmallIntegerField(verbose_name='收支类型', choices=OPERATE_TYPE_CHOICES)
    point_type = models.SmallIntegerField(verbose_name='积分类型', choices=POINT_TYPE_CHOICES, default=2)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    point_balance = models.DecimalField(verbose_name='积分余额', max_digits=10, decimal_places=2, default=0)
    point_order = models.CharField(verbose_name='关联订单', max_length=64, null=True, blank=True)
    expired_time = models.DateTimeField(verbose_name='过期时间', null=True, blank=True)
    explain = models.CharField(verbose_name='说明', max_length=64)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='消费商户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='交易金额', max_digits=10, decimal_places=2, default=0)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    shop_id = models.CharField(verbose_name='商户id', max_length=32, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=32, null=True, blank=True)
    level = models.ForeignKey('users.Level', on_delete=models.SET_NULL, verbose_name='层级', null=True, blank=True)

    class Meta:
        db_table = 'tb_point_record_4'
        verbose_name = '用户积分记录'
        verbose_name_plural = verbose_name


class PointRecord5(models.Model):
    '''用户积分记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '收入'),
        (2, '支出'),
        (3, '已过期')
    )

    POINT_TYPE_CHOICES = (
        (1, '注册'),
        (2, '消费'),
        (3, '邀请'),
        (4, '活动'),
        (5, '签到')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    operate_type = models.SmallIntegerField(verbose_name='收支类型', choices=OPERATE_TYPE_CHOICES)
    point_type = models.SmallIntegerField(verbose_name='积分类型', choices=POINT_TYPE_CHOICES, default=2)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    point_balance = models.DecimalField(verbose_name='积分余额', max_digits=10, decimal_places=2, default=0)
    point_order = models.CharField(verbose_name='关联订单', max_length=64, null=True, blank=True)
    expired_time = models.DateTimeField(verbose_name='过期时间', null=True, blank=True)
    explain = models.CharField(verbose_name='说明', max_length=64)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='消费商户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='交易金额', max_digits=10, decimal_places=2, default=0)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    shop_id = models.CharField(verbose_name='商户id', max_length=32, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=32, null=True, blank=True)
    level = models.ForeignKey('users.Level', on_delete=models.SET_NULL, verbose_name='层级', null=True, blank=True)

    class Meta:
        db_table = 'tb_point_record_5'
        verbose_name = '用户积分记录'
        verbose_name_plural = verbose_name


class PointRecord6(models.Model):
    '''用户积分记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '收入'),
        (2, '支出'),
        (3, '已过期')
    )

    POINT_TYPE_CHOICES = (
        (1, '注册'),
        (2, '消费'),
        (3, '邀请'),
        (4, '活动'),
        (5, '签到')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    operate_type = models.SmallIntegerField(verbose_name='收支类型', choices=OPERATE_TYPE_CHOICES)
    point_type = models.SmallIntegerField(verbose_name='积分类型', choices=POINT_TYPE_CHOICES, default=2)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    point_balance = models.DecimalField(verbose_name='积分余额', max_digits=10, decimal_places=2, default=0)
    point_order = models.CharField(verbose_name='关联订单', max_length=64, null=True, blank=True)
    expired_time = models.DateTimeField(verbose_name='过期时间', null=True, blank=True)
    explain = models.CharField(verbose_name='说明', max_length=64)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='消费商户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='交易金额', max_digits=10, decimal_places=2, default=0)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    shop_id = models.CharField(verbose_name='商户id', max_length=32, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=32, null=True, blank=True)
    level = models.ForeignKey('users.Level', on_delete=models.SET_NULL, verbose_name='层级', null=True, blank=True)

    class Meta:
        db_table = 'tb_point_record_6'
        verbose_name = '用户积分记录'
        verbose_name_plural = verbose_name


class PointRecord7(models.Model):
    '''用户积分记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '收入'),
        (2, '支出'),
        (3, '已过期')
    )

    POINT_TYPE_CHOICES = (
        (1, '注册'),
        (2, '消费'),
        (3, '邀请'),
        (4, '活动'),
        (5, '签到')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    operate_type = models.SmallIntegerField(verbose_name='收支类型', choices=OPERATE_TYPE_CHOICES)
    point_type = models.SmallIntegerField(verbose_name='积分类型', choices=POINT_TYPE_CHOICES, default=2)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    point_balance = models.DecimalField(verbose_name='积分余额', max_digits=10, decimal_places=2, default=0)
    point_order = models.CharField(verbose_name='关联订单', max_length=64, null=True, blank=True)
    expired_time = models.DateTimeField(verbose_name='过期时间', null=True, blank=True)
    explain = models.CharField(verbose_name='说明', max_length=64)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='消费商户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='交易金额', max_digits=10, decimal_places=2, default=0)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    shop_id = models.CharField(verbose_name='商户id', max_length=32, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=32, null=True, blank=True)
    level = models.ForeignKey('users.Level', on_delete=models.SET_NULL, verbose_name='层级', null=True, blank=True)

    class Meta:
        db_table = 'tb_point_record_7'
        verbose_name = '用户积分记录'
        verbose_name_plural = verbose_name


class PointRecord8(models.Model):
    '''用户积分记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '收入'),
        (2, '支出'),
        (3, '已过期')
    )

    POINT_TYPE_CHOICES = (
        (1, '注册'),
        (2, '消费'),
        (3, '邀请'),
        (4, '活动'),
        (5, '签到')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    operate_type = models.SmallIntegerField(verbose_name='收支类型', choices=OPERATE_TYPE_CHOICES)
    point_type = models.SmallIntegerField(verbose_name='积分类型', choices=POINT_TYPE_CHOICES, default=2)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    point_balance = models.DecimalField(verbose_name='积分余额', max_digits=10, decimal_places=2, default=0)
    point_order = models.CharField(verbose_name='关联订单', max_length=64, null=True, blank=True)
    expired_time = models.DateTimeField(verbose_name='过期时间', null=True, blank=True)
    explain = models.CharField(verbose_name='说明', max_length=64)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='消费商户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='交易金额', max_digits=10, decimal_places=2, default=0)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    shop_id = models.CharField(verbose_name='商户id', max_length=32, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=32, null=True, blank=True)
    level = models.ForeignKey('users.Level', on_delete=models.SET_NULL, verbose_name='层级', null=True, blank=True)

    class Meta:
        db_table = 'tb_point_record_8'
        verbose_name = '用户积分记录'
        verbose_name_plural = verbose_name


class PointRecord9(models.Model):
    '''用户积分记录'''

    OPERATE_TYPE_CHOICES = (
        (1, '收入'),
        (2, '支出'),
        (3, '已过期')
    )

    POINT_TYPE_CHOICES = (
        (1, '注册'),
        (2, '消费'),
        (3, '邀请'),
        (4, '活动')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='添加时间', auto_now_add=True)
    operate_type = models.SmallIntegerField(verbose_name='收支类型', choices=OPERATE_TYPE_CHOICES)
    point_type = models.SmallIntegerField(verbose_name='积分类型', choices=POINT_TYPE_CHOICES, default=2)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    point_balance = models.DecimalField(verbose_name='积分余额', max_digits=10, decimal_places=2, default=0)
    point_order = models.CharField(verbose_name='关联订单', max_length=64, null=True, blank=True)
    expired_time = models.DateTimeField(verbose_name='过期时间', null=True, blank=True)
    explain = models.CharField(verbose_name='说明', max_length=64)
    merchant = models.ForeignKey('merchants.Merchant', verbose_name='消费商户', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    amount = models.DecimalField(verbose_name='交易金额', max_digits=10, decimal_places=2, default=0)
    pay_time = models.DateTimeField(verbose_name='交易时间', null=True, blank=True)
    shop_id = models.CharField(verbose_name='商户id', max_length=32, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=32, null=True, blank=True)
    level = models.ForeignKey('users.Level', on_delete=models.SET_NULL, verbose_name='层级', null=True, blank=True)

    class Meta:
        db_table = 'tb_point_record_9'
        verbose_name = '用户积分记录'
        verbose_name_plural = verbose_name


point_record_model_map = {
    0: PointRecord0,
    1: PointRecord1,
    2: PointRecord2,
    3: PointRecord3,
    4: PointRecord4,
    5: PointRecord5,
    6: PointRecord6,
    7: PointRecord7,
    8: PointRecord8,
    9: PointRecord9,
}
table_num = 10


def get_point_record_db_model(user_id):
    key = user_id % table_num
    return point_record_model_map[key]


class PointOrderInfo():
    '''交易订单'''

    ORDER_TYPE_CHOICES = (
        (1, '微信'),
        (2, '支付宝'),
        (3, '云闪付')
    )

    IS_POINT_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    program_id = models.CharField(verbose_name='应用id', max_length=18)
    unionid  = models.CharField(verbose_name='平台unionid', max_length=32)
    wyf_openid = models.CharField(verbose_name='微邮付⼩程序openid', max_length=32)
    shop_id = models.CharField(verbose_name='商户id', max_length=32)
    money = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='支付金额', default=0)
    order_type = models.SmallIntegerField(verbose_name='订单类型', choices=ORDER_TYPE_CHOICES, default=1)
    out_trade_no = models.CharField(verbose_name='微邮付订单号', max_length=32)
    pay_time = models.DateTimeField(verbose_name='支付时间')
    transaction_id = models.CharField(verbose_name='付款凭证中的条码单号', max_length=64, unique=True)
    channel_trade_no = models.CharField(verbose_name='微信⽀付/云闪付单号', max_length=64)
    short_key = models.CharField(verbose_name='商户号', max_length=10)
    is_point = models.SmallIntegerField(verbose_name='是否累计积分', choices=IS_POINT_CHOICES, default=0)
    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='所属用户', on_delete=models.SET_NULL, null=True, blank=True)

    class Meta:
        db_table = 'tb_o_point_order_info'
        verbose_name = '交易订单'
        verbose_name_plural = verbose_name


class BindCardOrder(models.Model):

    ORDER_STATUS_CHOICES = (
        (1, '待支付'),
        (2, '已支付'),
        (3, '支付失败'),
        (4, '已退款'),
        (5, '退款失败')
    )

    PRIZE_STATUS_CHOICES = (
        (1, '初始状态'),
        (2, '待领取'),
        (3, '已领取'),
        (4, '领取失败'),
        (5, '已作废'),
        (6, '待抽奖')
    )

    BANK_TYPE_CHOICES = (
        (1, '邮储借记卡'),
        (2, '邮储信用卡'),
        (3, '其他')
    )

    IS_EXCHANGE_CHOICES = (
        (0, '未兑换'),
        (1, '已兑换')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='用户', on_delete=models.CASCADE)
    amount = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='支付金额', default=0)
    order_status = models.SmallIntegerField(verbose_name='订单状态', choices=ORDER_STATUS_CHOICES, default=1)
    prize_status = models.SmallIntegerField(verbose_name='订单状态', choices=PRIZE_STATUS_CHOICES, default=1)
    bank_type_sign = models.SmallIntegerField(verbose_name='银行标识', choices=BANK_TYPE_CHOICES, default=3)
    description = models.CharField(verbose_name='商品描述', max_length=127)
    out_trade_no = models.CharField(verbose_name='商户订单号', max_length=32, unique=True)
    create_time = models.DateTimeField(auto_now_add=True, verbose_name='创建时间')
    user_received_account = models.CharField(verbose_name='退款入账账户', max_length=64, null=True, blank=True)
    refund_id = models.CharField(verbose_name='微信支付退款单号', max_length=32, null=True, blank=True)
    out_refund_no = models.CharField(verbose_name='商户退款单号', max_length=32, null=True, blank=True)
    transaction_id = models.CharField(verbose_name='交易单号', max_length=32)
    message = models.CharField(verbose_name='交易单号', max_length=128, null=True, blank=True)
    bank_type = models.CharField(verbose_name='付款银行类型', max_length=16, null=True, blank=True)
    success_time = models.DateTimeField(verbose_name='成功支付时间', null=True, blank=True)
    refund_time = models.DateTimeField(verbose_name='该笔交易的退款时间', null=True, blank=True)
    customizeactivity = models.ForeignKey('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.SET_NULL, null=True, blank=True)
    customizeactivityflipcards = models.OneToOneField('vouchers.CustomizeActivityFlipCARDS', verbose_name='奖励', on_delete=models.SET_NULL, null=True, blank=True)
    business_qrcode = models.CharField(verbose_name='绑卡邀请', max_length=12, null=True, blank=True)
    is_exchange = models.SmallIntegerField(verbose_name='银行标识', choices=IS_EXCHANGE_CHOICES, default=0)

    class Meta:
        db_table = 'tb_o_bind_card_order'
        verbose_name = '绑卡校验订单'
        verbose_name_plural = verbose_name


class JoinCustomizeActivity(models.Model):
    '''参与新手任务'''

    ACTIVITY_STATUS_CHOICES = (
        (0, '未参加'),
        (1, '进行中'),
        (2, '已完成')
    )

    IS_POPUP_CHOICES = (
        (0, '否'),
        (1, '是')
    )

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='参加时间', auto_now_add=True)
    customizeactivity = models.ForeignKey('vouchers.CustomizeActivity', verbose_name='活动', on_delete=models.CASCADE)
    is_join = models.SmallIntegerField(verbose_name='活动状态', choices=ACTIVITY_STATUS_CHOICES, default=0)
    is_popup = models.SmallIntegerField(verbose_name='活动状态', choices=IS_POPUP_CHOICES, default=0)
    join_time = models.DateTimeField(verbose_name='参加时间', null=True, blank=True)
    count = models.IntegerField(verbose_name='完成笔数', default=0)

    class Meta:
        db_table = 'tb_customize_activity_join'
        verbose_name = '参与新手任务'
        verbose_name_plural = verbose_name


class SignIn0(models.Model):
    '''用户签到记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='签到时间', auto_now_add=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    award_point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    date = models.CharField(verbose_name='签到日期', max_length=16)
    month = models.CharField(verbose_name='签到日期', max_length=8)

    class Meta:
        db_table = 'tb_sign_in_0'
        verbose_name = '用户签到记录'
        verbose_name_plural = verbose_name


class SignIn1(models.Model):
    '''用户签到记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='签到时间', auto_now_add=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    award_point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    date = models.CharField(verbose_name='签到日期', max_length=16)
    month = models.CharField(verbose_name='签到日期', max_length=8)

    class Meta:
        db_table = 'tb_sign_in_1'
        verbose_name = '用户签到记录'
        verbose_name_plural = verbose_name


class SignIn2(models.Model):
    '''用户签到记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='签到时间', auto_now_add=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    award_point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    date = models.CharField(verbose_name='签到日期', max_length=16)
    month = models.CharField(verbose_name='签到日期', max_length=8)

    class Meta:
        db_table = 'tb_sign_in_2'
        verbose_name = '用户签到记录'
        verbose_name_plural = verbose_name


class SignIn3(models.Model):
    '''用户签到记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='签到时间', auto_now_add=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    award_point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    date = models.CharField(verbose_name='签到日期', max_length=16)
    month = models.CharField(verbose_name='签到日期', max_length=8)

    class Meta:
        db_table = 'tb_sign_in_3'
        verbose_name = '用户签到记录'
        verbose_name_plural = verbose_name


class SignIn4(models.Model):
    '''用户签到记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='签到时间', auto_now_add=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    award_point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    date = models.CharField(verbose_name='签到日期', max_length=16)
    month = models.CharField(verbose_name='签到日期', max_length=8)

    class Meta:
        db_table = 'tb_sign_in_4'
        verbose_name = '用户签到记录'
        verbose_name_plural = verbose_name


class SignIn5(models.Model):
    '''用户签到记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='签到时间', auto_now_add=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    award_point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    date = models.CharField(verbose_name='签到日期', max_length=16)
    month = models.CharField(verbose_name='签到日期', max_length=8)

    class Meta:
        db_table = 'tb_sign_in_5'
        verbose_name = '用户签到记录'
        verbose_name_plural = verbose_name


class SignIn6(models.Model):
    '''用户签到记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='签到时间', auto_now_add=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    award_point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    date = models.CharField(verbose_name='签到日期', max_length=16)
    month = models.CharField(verbose_name='签到日期', max_length=8)

    class Meta:
        db_table = 'tb_sign_in_6'
        verbose_name = '用户签到记录'
        verbose_name_plural = verbose_name


class SignIn7(models.Model):
    '''用户签到记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='签到时间', auto_now_add=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    award_point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    date = models.CharField(verbose_name='签到日期', max_length=16)
    month = models.CharField(verbose_name='签到日期', max_length=8)

    class Meta:
        db_table = 'tb_sign_in_7'
        verbose_name = '用户签到记录'
        verbose_name_plural = verbose_name


class SignIn8(models.Model):
    '''用户签到记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='签到时间', auto_now_add=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    award_point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    date = models.CharField(verbose_name='签到日期', max_length=16)
    month = models.CharField(verbose_name='签到日期', max_length=8)

    class Meta:
        db_table = 'tb_sign_in_8'
        verbose_name = '用户签到记录'
        verbose_name_plural = verbose_name


class SignIn9(models.Model):
    '''用户签到记录'''

    customeruservice = models.ForeignKey('users.CustomerUserVice', verbose_name='领取用户', on_delete=models.CASCADE)
    create_time = models.DateTimeField(verbose_name='签到时间', auto_now_add=True)
    point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    award_point = models.DecimalField(verbose_name='积分', max_digits=10, decimal_places=2, default=0)
    date = models.CharField(verbose_name='签到日期', max_length=16)
    month = models.CharField(verbose_name='签到日期', max_length=8)

    class Meta:
        db_table = 'tb_sign_in_9'
        verbose_name = '用户签到记录'
        verbose_name_plural = verbose_name


sign_in_model_map = {
    0: SignIn0,
    1: SignIn1,
    2: SignIn2,
    3: SignIn3,
    4: SignIn4,
    5: SignIn5,
    6: SignIn6,
    7: SignIn7,
    8: SignIn8,
    9: SignIn9,
}


def get_sign_in_db_model(user_id):
    key = user_id % table_num
    return sign_in_model_map[key]


class ScoutTheStoreLeaderboard(models.Model):
    '''探店排行'''

    city = models.CharField(verbose_name='地市', max_length=32)
    merhant_name = models.CharField(verbose_name='商户', max_length=64)
    creator = models.CharField(verbose_name='创作者', max_length=64, null=True, blank=True)
    likes = models.IntegerField(verbose_name='点赞数')
    update_time = models.DateTimeField(verbose_name='更新时间')

    class Meta:
        db_table = 'tb_scout_the_store_Leaderboard'
        verbose_name = '探店排行'
        verbose_name_plural = verbose_name


class ScoutTheStoreLeaderboardRewards(models.Model):
    '''探店排行奖励'''

    REWARD_TYPE_CHOICES = (
        (1, '小邮美宿券'),
        (2, 'ipad'),
        (3, '红包')
    )

    REWARD_STATUS_CHOICES = (
        (1, '待领取'),
        (2, '已领取'),
        (3, '领取失败'),
        (4, '领取中')
    )

    award_time_begin = models.DateTimeField(verbose_name='领奖时间(起)')
    award_time_end = models.DateTimeField(verbose_name='领奖时间止')
    mobile = models.CharField(verbose_name='中奖手机号', max_length=11)
    reward_type = models.SmallIntegerField(verbose_name='奖励类型', choices=REWARD_TYPE_CHOICES, default=1)
    reward_status = models.SmallIntegerField(verbose_name='奖励状态', choices=REWARD_STATUS_CHOICES, default=1)
    reward_name = models.CharField(verbose_name='名称', max_length=32)
    receiver = models.CharField(max_length=20, verbose_name='收货人', null=True, blank=True)
    contact_way = models.CharField(max_length=20, verbose_name='收货人联系方式', null=True, blank=True)
    province = models.CharField(max_length=20, verbose_name='省', null=True, blank=True)
    city = models.CharField(max_length=20, verbose_name='市', null=True, blank=True)
    district = models.CharField(max_length=20, verbose_name='区', null=True, blank=True)
    place = models.CharField(max_length=128, verbose_name='门牌号', null=True, blank=True)
    address = models.CharField(max_length=128, verbose_name='地址', null=True, blank=True)
    longitude = models.CharField(verbose_name='经度', max_length=32, null=True, blank=True)
    latitude = models.CharField(verbose_name='纬度', max_length=32, null=True, blank=True)
    amount = models.DecimalField(verbose_name='奖金', max_digits=10, decimal_places=2, default=0)
    popularity = models.IntegerField(verbose_name='人气')
    rank = models.IntegerField(verbose_name='排名')
    login_id = models.CharField(verbose_name='支付宝账号', max_length=32, null=True, blank=True)
    realname = models.CharField(verbose_name='支付宝账号实名', max_length=32, null=True, blank=True)
    cashactivitydata = models.OneToOneField('cashbonus.CashActivityData', verbose_name='是否中奖', on_delete=models.SET_NULL, null=True, blank=True)
    return_msg = models.TextField(null=True, blank=True)
    business_no = models.CharField(verbose_name='商户号', max_length=10)
    reward_lists = models.TextField(verbose_name='奖品详情', null=True, blank=True)

    class Meta:
        db_table = 'tb_scout_the_store_leaderboard_rewards'
        verbose_name = '探店排行'
        verbose_name_plural = verbose_name